<template>
  <ych-modal
    :fullscreen="true"
    :bodyStyle="bodyStyle"
    :title="$t('m.common.button.preview')"
    :visible="visible"
    :footer="null"
    :destroyOnClose="true"
    @cancel="handleCancel">
    <view-layout-redirect ref="viewLayoutRedirect"></view-layout-redirect>
  </ych-modal>
</template>
<script>

import YchConstant from "@/api/YchConstant";
import {postAction} from '@/api/manage'
import ViewLayoutRedirect from "../redirect/ViewLayoutRedirect";

export default {
  name: "LayoutPreview",
  props: {
    type: String
  },
  data() {
    return {
      visible: false,
      objectCode: null,
      jsonData: {},
      bodyStyle: {
        padding: '10px',
        margin: '',
        backgroundColor: '#ececec'
      },
      url: {
        getMainViewModelForPreview: YchConstant.PREFIX_EFORM + '/engine/viewEngine/getMainViewModelForPreview'
      }
    };
  },
  components: {
    ViewLayoutRedirect
  },
  methods: {
    handleCancel() {
      this.visible = false;
    },
    show() {
      this.visible = true;
      this.$nextTick(() => {
        postAction(this.url.getMainViewModelForPreview + `?objectCode=${this.objectCode || ''}&type=${this.type}`, this.jsonData).then((res) => {
          if (res.success) {
            this.$refs.viewLayoutRedirect.reLoadForPreview(this.jsonData, res.result);
          } else {
            this.messageUtil.warning(res.message)
          }
        })
      })
    }
  }
};
</script>
